<?php
namespace Admin\Controller;
use Think\Controller;
/**
 * 活动管理控制器
 */
class ActivityController extends AdminController{
  /**
   * 活动列表
   */
  public function index(){

             $page=I('get.page','1','strip_tags');
             $count=M('activity')->count();
             $pagearr= getPageArr($page,C('PAGESIZE'),$count);
             $re=M('activity')->limit($pagearr['start'],$pagearr['pagesize'])->select();
   $this->assign('re',$re);
   $this->display();

}
/**
 * 添加活动
 */
public function append(){
  if($_POST){

    $config['path']=C('Admin_IMG_PATH');
    $config['maxsize']=C('IMG_MAX_SIZE');
    $img=imgUpload($config);
    $imginfo=$img['activityimg'];
 
    if(!empty($imginfo['name']))
    {
      ///$data['activityimg']=C('Admin_IMG_PATH').$imginfo['savepath'].$imginfo['savename'];
     $data['activityimg']= substr(C('Admin_IMG_PATH'),1).$imginfo['savepath'].$imginfo['savename'];
    }
    $data['theme']=I("post.theme",'','strip_tags');
    $data['opentime']=strtotime(I("post.opentime",0,"strip_tags"));
    $data['endtime']=strtotime(I("post.endtime",0,"strip_tags"));
    $data['state']=I("post.state",'','strip_tags');
          $re=M('activity')->add($data);
          if($re>0){

              $this->redirect("Activity/index");
         }
    }else{


        $this->display();
   }
}

  /**
   * 检测活动的唯一性
   */
  public function weiyi(){
    $theme=$_GET['name'];
    $re=M('supper_user')->where("theme='%s'",$theme)->getField("id");
    
    if(is_null($re)){
      $data = array('status'=>200,'code'=>'success','info'=>'无效的手机号');
      echo json_encode($data);

    }else{
      $data = array('status'=>404,'code'=>'error','info'=>'改活动名已存在');
      echo json_encode($data);

    }

  }
/**
 * 活动编辑
 */

     public function edit(){
      if(IS_POST){
        $where['id']=$_GET['id'];
     $data['theme']=I("post.theme",'','strip_tags');
    $data['opentime']=strtotime(I("post.opentime",0,"strip_tags"));
    $data['endtime']=strtotime(I("post.endtime",0,"strip_tags"));
    $data['state']=I("post.state",'',"strip_tags");
 $config['path']=C('Admin_IMG_PATH');
    $config['maxsize']=C('IMG_MAX_SIZE');
    $img=imgUpload($config);
    $imginfo=$img['activityimg'];
    if(!empty($imginfo['name']))
    {
      $data['activityimg']=substr(C('Admin_IMG_PATH'),1).$imginfo['savepath'].$imginfo['savename'];
    }
          $re=M('activity')->where($where)->save($data);


          
            $this->redirect("Activity/index");
       

      }else{
        $where['id']=$_GET['id'];
          $re=M('activity')->where($where)->find();

          $this->assign('re',$re);

          $this->display("");

      }
          

     }


     /**
      * 删除活动
      */
    public function move(){
    $where['id']=$_GET['id'];
   
    $row=M('activity')->where($where)->delete();

    echo "<script>alert('活动删除成功');location.href='/index.php/Admin/Activity/index'</script>";
  
   }


}